﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRM.Entity;
using HRM.BIZ;
using WebUI.UserControls;

namespace WebUI.Pages
{
    public partial class PositionManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadData();
            }
        }

        protected void LoadData()
        {
            PositionBiz posBiz = new PositionBiz();
            ucPositionManagement.DataSource = posBiz.GetAll();
            ucPositionManagement.LoadItemList();
        }

        protected void ucPositionManagement_AddItem(object sender, ItemManagementEventArgs e)
        {
            PositionBiz posBiz = new PositionBiz();
            Position pos = new Position();
            pos.Name = e.Name;
            posBiz.Add(pos);
            (Master as DefaultMasterPage).RunStartupScript("displayMessage('Thêm thành công')");
            ucPositionManagement.SetActionPanelVisible(false);
            LoadData();
        }

        protected void ucPositionManagement_SaveEditItem(object sender, ItemManagementEventArgs e)
        {
            PositionBiz posBiz = new PositionBiz();
            Position pos = posBiz.GetByID(e.ID);
            if (pos != null)
            {
                pos.Name = e.Name;
                posBiz.Update(pos);
                (Master as DefaultMasterPage).RunStartupScript("displayMessage('Cập nhật thành công')");
                ucPositionManagement.SetActionPanelVisible(false);
                LoadData();
            }
        }

        protected void ucPositionManagement_DeleteItem(object sender, ItemManagementEventArgs e)
        {
            PositionBiz posBiz = new PositionBiz();
            posBiz.Delete(e.ID);
            LoadData();
        }
    }
}
